<?     

     
$cookie_view    = get_profile_value($host, "listview");      

#BEGIN article list toolbar     
print "<form action='" . $href . "' method='get' style='margin:0'>  ";     
           
echo "<div style='padding:3px'>";   
echo "<span class='button'>";  
if (array_search($group_name,$sg_c)===false)     
{     
    echo "<img style='filter:gray' align=absmiddle src='add_to_favorite.gif'>";
    echo "&nbsp;<a href=\"javascript:fb_edit ('a', 'subscribe')\">Subscribe</a>";     
}     
else     
{     
    echo "<img align=absmiddle src='add_to_favorite.gif'>";
    echo "&nbsp;<a href=\"javascript:fb_edit ('a', 'unsubscribe')\">Unsubscribe</a>";     
}  
echo "</span>";     
             
#THUMBNAIL VIEW TOGGLE     
echo "&nbsp;<span class='button'>View As: ";
if ($cookie_view=="thumbnail")     
{     
    echo "Thumbnails&nbsp;";     
    echo "<a href=\"javascript:fb_edit('a','changeview')\">List</a>";     
}     
else     
{     
    echo "<a href=\"javascript:fb_edit('a','changeview')\">Thumbnails</a>&nbsp;";     
    echo "List";     
}   
echo "</span>";

  #PREVIEW TOGGLE     
if ($group_name!="")     
{     
    echo "&nbsp;<span class='button'>";     
    if ($cookie_preview=="preview")     
    {     
        echo "<img align='absmiddle' src='image.php?i=s'     
            >&nbsp;<a style='text-decoration:none' href=\"javascript:fb_edit('v', 'nopreview')\"     
            >Preview off</a>   ";     
    }      
    else     
    {     
        echo "<img align='absmiddle' src='image.php?i=s' style='filter:gray'     
            >&nbsp;<a href=\"javascript:fb_edit('v', 'preview')\" style='text-decoration:none;color:#006633'     
            >Preview on</a>   ";     
    }     
    echo "</span>&nbsp;";         
} 
#echo "&nbsp;<a href=\"javascript:snapshot()\">Snapshot</a>&nbsp;";     
#END article list toolbar     



raise_event (EVENT_ARTICLE_LIST_BEGIN, $cookie_preview);      

$collated = article_collate ($user, $pass, $group_name, $start_at, $search_param, $search_user);


$page_list   = $collated["pages"];     
$list_count  = $collated["count"];     
$result      = $collated["result"];     
   
$cache_event = true;
 #BEGIN: compress article list into pattern arrays     
$article_loop_count     = 0;              
$start_idx              = $start_at; # ( count($page_list) - $start_at ) - 1;     
$end_idx                = $start_idx + 1;      
$start_id               = $page_list[$start_idx];     
$end_id                 = $page_list[$end_idx];       
$stopper                = min($start_id, $end_id);     
$patterns               = array();     
$nullpattern            = array();    
# echo $stopper   . "--" . $result["articles"][0]->nntp_message_id . "--";
foreach($result["articles"] as $article)     
{      
    if ($article->nntp_message_id>=$stopper&&$article_loop_count<RESULT_PAGE_SIZE)     
    {      
        $article_loop_count++;      
        $pattern_is_present = false;     
        while (list ($regex_expression, $matching_articles) = each ($patterns))      
        {     
            $pattern_test_one = preg_match ($regex_expression, $article->subject, $tmp);     
            if ($pattern_test_one)     
            {       
                $pattern_test_two = true;     
                if (count($patterns[$regex_expression]) > 0)     
                {     
                    $previous_article_from = $patterns[$regex_expression][count($patterns[$regex_expression])-1]->from["email"];     
                    $this_article_from     = $article->from["email"];      
                    $pattern_test_two      = $previous_article_from==$this_article_from;     
                }     
                     
                if ($pattern_test_two)     
                {        
                    $patterns[$regex_expression][] = $article;     
                    $pattern_is_present = true;     
                    break;     
                }  
            }      
        }       
             
        reset ($patterns);     
             
        $pattern     = preg_quote($article->subject);       
        $pattern     = preg_replace (array ("/(\d+)/", "/\//"), array("(\d+)", "\\/"), $pattern);       
        $pattern     = "/". trim($pattern) . "/i";     
             
        if (! array_key_exists($pattern, $patterns))      
        {     
            $patterns[$pattern] = array($article);     
        }       
    }     
}      

$start_page = 1 + ($start_at * RESULT_PAGE_SIZE);
$end_page   = $start_page + $article_loop_count;   
     
echo $start_page . ' to ' . $end_page . " of " . $list_count . " items, " . count ($patterns) . " distinct articles. ";    
echo "</div>"; 

$movies        = array();     
$pictures      = array();     
$from_break    = $cookie_preview=="preview" ? "<br>" : "";     
$row_count     = 0;     
$row_data      = "";     
$ghost_data    = "";     
$preview       = false;       
$unique        = array();       
while (list ($a, $pattern) = each ($patterns))      
{  # create row-data for each subject pattern     
    $row_count++;     
    $article       = $pattern[0];      
    $id            = $article->nntp_message_id;     
    $subject       = $article->subject;       
    $from          = $article->from;     
    $byte_count    = $article->byte_count;     
    $line_count    = $article->line_count;     
    $age           = number_format( (time() - $article->date) / 86400, 1 );       
         
    $exist_test    = preg_match('/([_!@\.\+,\-a-zA-Z()\s\d]*\.\w{3,4})/', $article->subject, $name_map);     
    $media_test    = preg_match(REGEX_MASK_MEDIA, $article->subject, $media_map);     
    $image_test    = preg_match(REGEX_MASK_PICTURE, $article->subject, $image_map);      
    $exclude_test  = preg_match(REGEX_MASK_EXCLUDE, $subject, $mpg);     
    $exclude_test  = $exclude_test || $media_test;     
    $subject       = clean_subject($subject);      
          
    $row_style     = count($pattern) > 1 ? " style='font-weight:bold;color:navy;cursor:hand' " : " style='cursor:hand' ";     
    $row_icon      = count($pattern) > 1 ? "splus1.gif" : "sub.gif";     
         
    $onclick       =  "nn.choose('" . $id . "', '" . ($exclude_test ? "0" : "1") . "')";       
           
    if ($preview==false)     
    {     
        $preview = $article;     
        $preview_onclick = $onclick;     
    }     
    if ($row_count==count($patterns))     
    {     
        $row_icon  = count($pattern) > 1?"b_splus.gif":"b_sub.gif";     
    }      
         
    $from_name = htmlentities($from["name"]);     
    $from_mail = htmlentities($from["email"]);     
    if (array_search($id, $unique)===false)     
    {     
             
        $bgcolor="white";     
             
        $saveas     = false;     
          
        $exist_test = check_media_cache ($article->subject);     
        if ($exist_test)     
        {                      
            $saveas    = $exist_test["saveas"];    
        }       
        if ($media_test)     
        {         
             $nfo=array("id"=>$id,"subject"=>$saveas?$saveas:$media_map[1].".".$media_map[2],"byte_count"=>$byte_count,"count"=>count($pattern),"type"=>1,"onclick"=>$onclick);     
             $pictures[] = $nfo;     
        }             
        else if ( $image_test )     
        {     
             $nfo=array("id"=>$id,"subject"=>$saveas?$saveas:$image_map[1].".".$image_map[2],"byte_count"=>$byte_count,"count"=>count($pattern),"type"=>0,"onclick"=>$onclick);     
             $pictures[] = $nfo;     
        }      
             
             
        # ARTICLE ROW ELEMENT     
        $is="nn.expand('$id')";    
        $is="launch_pictures('$id','$image_test')";   
         
        $row_data .= "<tr bgcolor=$bgcolor id='" . $id . "'><td nowrap><img src='images/" . $row_icon . "' onclick=\"$is\" style='cursor:hand'></td>";        
        $row_data .= "<td nowrap class='row'>" . $line_count ."&nbsp;</td>";        
        $row_data .= "<td nowrap class='row'>&nbsp;&nbsp;<span ";        
        $row_data .= " onselectstart=\"return false\" onclick=\"" . $onclick . "\" " . $row_style . ">";        
        $row_data .= "". $subject ."</span>&nbsp;</td>";        
        $row_data .= "<td nowrap class='row'>&nbsp;&nbsp;<a href='javascript:fb_edit(\"u\",\"" . $from_name . "\")'>". $from_name ."</a>&nbsp;</td>";        
        $row_data .= "<td nowrap class='row' id='4_".$id."'>&nbsp;&nbsp;". count($pattern) ."&nbsp;</td>";        
        $row_data .= "<td nowrap class='row'>&nbsp;&nbsp;". $age . "d&nbsp;</td>";        
        $row_data .= "<td nowrap class='row'>&nbsp;&nbsp;<span>". $byte_count ."</span>&nbsp;</td>";        
        $row_data .= "<td nowrap class='row' width='100%'>&nbsp;</td>";        
        $row_data .= "</tr>";     
             
        # hidden data supports client-side scripts     
        $ghost_data .= "<span style='display:none' id='0_".$id."'>" . $subject . "</span>";      
        $ghost_data .= "<span style='display:none' id='1_".$id."'>" . $from_name ."&nbsp;" . $from_break      
                    . "<a href=\"mailto:" . $from_mail ."\">". $from_mail . "</a></span>";             
        $ghost_data .= "<span style='display:none' id='2_".$id."'>" . date("D M d, Y h:i:s A", $article->date) . "</span> ";     
        $ghost_data .= "<span style='display:none' id='3_".$id."'>" . $byte_count . "</span>";      
                                                                                                                                                                           
        $msg_id    = str_replace("<", "", $article->message_id);                                                                                                                                                                                                                 
        $msg_id    = str_replace(">", "", $msg_id);         
             
        raise_event (EVENT_ARTICLE_LIST_ROW_COMPLETE, 0, $id, $article->subject, $byte_count, $saveas, $msg_id);     
    }     
    $unique [] = $id;     
                        
                      
    for ($e=1;$e<count ($pattern);$e++)     
    {      
        $article       = $pattern[$e];      
        $sub_id        = $article->nntp_message_id;      
        $subject       = $article->subject;       
        $from          = $article->from;     
        $age           = number_format( (time() - $article->date) / 86400, 1 );     
        $byte_count    = $article->byte_count;     
        $line_count    = $article->line_count;     
        $exclude_test  = preg_match(REGEX_MASK_EXCLUDE, $subject, $mpg);     
        $subject       = clean_subject($article->subject);      
        $onclick       = "nn.choose('" . $sub_id . "', '" . ($exclude_test ? "0" : "1") . "')";       
        $row_icon      = $e==count($pattern)-1 ? "b_sub.gif":"sub.gif";      
        $from_name     = htmlentities($from["name"]);     
        $from_mail     = htmlentities($from["email"]);     
             
        if ($media_test)     
        {      
             $onclick =  "transfer_in('" . $sub_id . "')";        
        }      
             

        $exist_test = check_media_cache ($article->subject);     
        $bgcolor="white";       
        $saveas="";     
        if ($exist_test)     
        {                             
            $saveas    = $exist_test["saveas"];       
        }     
             
             
             
        if (array_search($sub_id, $unique)===false)     
        {     
                                                                                                                          
               $msg_id    = str_replace("<", "", $article->message_id);                                                                                                                                                                                                                 
               $msg_id    = str_replace(">", "", $msg_id);   
             raise_event (EVENT_ARTICLE_SUB_ROW_COMPLETE, $id, $sub_id, $article->subject, $byte_count, $saveas, $msg_id);      
        }     
        $unique [] = $sub_id;     
    }       
}      
         
         
#LIST VIEW HTML     
$row_data = "<table cellspacing='0' cellpadding='0' style='border-bottom:solid 1px silver'>     
             <tr bgcolor='gainsboro'>     
                     <td nowrap><img src='image.php?i=g'></td>     
                     <td nowrap class='listheader'>&nbsp;<font color='gray'>Lines</font></td>     
                     <td nowrap class='listheader'>&nbsp;<font color='gray'>Subject</font></td>      
                     <td nowrap class='listheader'>&nbsp;<font color='gray'>From</font></td>   
                     <td nowrap class='listheader'>&nbsp;<font color='gray'>Count</font></td>      
                     <td nowrap class='listheader'>&nbsp;<font color='gray'>Age</font></td>     
                     <td nowrap class='listheader'>&nbsp;<font color='gray'>Bytes</font></td>     
                     <td nowrap class='listheader' width='100%'>&nbsp;</td>     
             </tr>" . $row_data . "";        
                      
#THUMBNAIL VIEW HTML     
$tmb=array ($pictures);     
$cls=array ("preview","movie");       
        
$sqr=160;     
$table="";     
$tmp="";     
      
$tmp.="<table cellpadding=4 align=center><tr>";        
for ($q=0;$q<count($pictures);$q++)     
{     
    $n=$pictures[$q]["type"];     
    $ix=-($n-1);     
    $id=$pictures[$q]["id"];     
    $ie=$id;     
         
    $if = cache_file ($id, "raw", $group_name);     
    $bi = cache_file ($id, $sqr, $group_name);   
       
    if (file_exists($if))     
    {       
        $ie.="*";     
    }     
    $ie="<img name='$ie' src='images/ico_image.jpg' border='0'>";    
    if (file_exists($bi))     
    {       
        $ie="<img id='img$id' src='$bi' asdf abcd>";     
    }     
     
    $cn=$pictures[$q]["count"];     
    $nm=$pictures[$q]["subject"];      
    $on=$pictures[$q]["onclick"];     
    $im="picture/$nntp_server/$group_name/$id/picture.jpg";      
    $is="$href?nntp=$nntp_server&message_id=$id&art_group=$group_name&a=slide";     
    $is="javascript:launch_pictures('$id')";     
    $in="$href?nntp=$nntp_server&message_id=$id&art_group=$group_name&a=nzb";     
         
    if ($n==1)     
    {     
        $ne="";               
        $ba="";     
    }     
    else if ($cn>1)     
    {     
        $ba="<a href=\"javascript:window.previews['p_$id']._play('A$id',-1)\"><img border='0' align=absmiddle src='images/back.bmp'></a>";               
        $ne="<a href=\"javascript:window.previews['p_$id']._play('A$id',1)\"><img border='0' align=absmiddle src='images/next.bmp'></a>";     
    }     
    else     
    {     
        $ba="<img border='0' style='filter:gray' align=absmiddle src='images/back.bmp'>";               
        $ne="<img border='0' style='filter:gray' align=absmiddle src='images/next.bmp'>";     
    }     
         
          
    $tmp.="<td id='" . $id . "' nowrap align=center>"; 
     
    # PREVIEW CONTAINER 
    $tmp.="<div onclick=\"$on\" class='$cls[$n]' id='p_" . $id . "' "; 
    $tmp.="style='width:".$sqr."px;height:".($sqr*.75)."px;overflow:hidden;'"; 
    $tmp.=">".$ie."</div>"; 
     
    $tmp.="<div align=left style='background-color:#e0e0e0;padding:2px;margin:1px'>      
                <a href=\"javascript:$on\"><img id='n_" . $id . "'  class='inline' border=0 align=absmiddle src='nntp_icon_info.gif'></a>     
                ".($n==0?"<a href=\"$im\" target=_blank><img align=absmiddle border=0 src='nntp_icon_download.gif'></a>":"")."     
                ".($n==0?"<a href=\"$is\"><img align=absmiddle border=0 src='nntp_icon_slideshow.gif'></a>":"")."     
                ".($n==1?"<a ".($cn>1?"href='$in'":"")." target=_blank><img align=absmiddle border=0 src='image.php?i=download'></a>":"")."     
                $ba $ne     
                </div><a href=\"javascript:$on\"><font size=1 face=verdana color=#004693>".chop_str($nm, 25)."</font></a> 
                <div align='center' id='counter_$id'><font size=1 face=verdana color=gray>1 of $cn</font></div></td>";     
    if (($q+1)%4==0)     
    {     
        $tmp .="</tr><tr>";     
    }     
}         
$tmp .="</tr></table>";         
$table.=$tmp;       


if ($cookie_view=="thumbnail")     
{     
    $row_data=$table;     
}     

                      
if ($preview)     
{     
    $image_test = preg_match(REGEX_MASK_PICTURE, $preview->subject,$image_map);      
    if ($image_test)     
    {     
        $src="loading.gif";     
    }          
}     
      
      
 #BEGIN: output table workspace     
 #----------------------------------------------------------------------------------- 
if ( count($result["articles"]) > 0)     
{     
    print "<table cellspacing='0' style='border-top:solid 1px white'><tr>";     
         
    if ($cookie_preview=="preview")     
    { #PREVIEW PANE     
        print "     
            <td width=250 valign=top  
                ><div style='background-color:white;margin:2px;overflow:auto;width:255px;border:none' class='resizeY'>      
                     <div id='dpreview' align=center     
                          style='width:240;     
                                 height:240px;     
                                 border:solid 1px silver;     
                                 overflow:hidden;display:none;     
                                 filter: progid:DXImageTransform.Microsoft.RandomDissolve();'>     
                               <img id='ipreview'      
                                    border='0'  onerror='image_fail ()'     
                                    onclick='launch_reg(this.src)'     
                                    src='" . $src . "'>      
                     </div>      
                     <div id='dserver'>     
                         <script>     
                         window.onload = function ()     
                         {     
                            desktop_background_resize();     
                            " . ($cookie_view=="thumbnail"?"load_images(1)":"") . ";     
                            " . $preview_onclick . ";     
                         }      
                         </script>     
                     </div>      
                     <pre>" . str_replace(">",">\n",$editor) . "</pre>
                </div>      
            </td>";     
    }     
         
         
         
    echo "<td valign='top' style='padding:2px'><div id='dbenchmark'>";      
         
    echo "<table width='100%' cellpadding='0' cellspacing='0'><tr><td style='padding:3px'>";         
    #PAGE LIST     
    include ("addon/pages.php");  
    
    echo "</td><td align='right'>";              

    echo "&nbsp;Find:";      
    echo " <input type='text' class='fancy' align='absmiddle' size=6 name=fi value='".$search_param."'> ";        
    echo " <input align='absmiddle' type='hidden' value='".$group_name."' name='g'> ";     
    echo " <input align='absmiddle' type='image' src='" . SEARCH_BUTTON . "' value=' Go '>   ";    
    echo " <a href='" . $href . "?" . ($search_user=="" ? "" : "u=") . ($search_param=="" ? "" : "fi=") . "&g=" . $group_name . "'>Reset</a> |";  
    echo " <a href='javascript:void(0)' onclick='supersearch ()'>Advanced...</a> ";
    
    echo "</td></tr></table>";    

    echo "<div>";        
    echo "<div id='ddetail' style='background-color:white;margin:2px;display:none' class='resizeXY'>This is the hidden detail panel</div>";       
    echo "<div id='dworkspace' onscroll='load_images (1)' style='background-color:white;margin:2px;";       
    echo "overflow:auto;' class='resizeXY'>$row_data</div>";     
    echo "</td></tr></table>";      
    echo script_block ("desktop_background_resize()");     
    echo $ghost_data;     
}      
else     
{     
    echo "<li>Search is complete. There are no records to display.</li>";     
    print_r ($result);     
}     
 #END: output table workspace     
      
      
print "</form><div id=dclip style='position:absolute;top:0;left:0'></div>";     
$code = "NNTP='$nntp_server';";    
$code .= "SQUARE='$sqr';";    
$code .= "USER='" . base64_encode (trim($user)) . "';";    
$code .= "PASS='" . base64_encode (trim($pass)) . "';"; //
echo script_block ($code);
?>   